﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LibAutoTransmeter;
using System.Text.RegularExpressions;

namespace AtPropEditor
{
    public partial class Form1 : Form
    {
        TranmeterProp myProp;
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            myProp = new TranmeterProp();
        }

        private void bysave_Click(object sender, EventArgs e)
        {
            myProp.isByte = cbIsbyte.Checked;
            myProp.isHost = cbIshost.Checked;
            myProp.mask = tbMask.Text;
            myProp.myTemplate = tbTemplate.Text;
            myProp.Name = tbName.Text;
            myProp.noMonitor = cbNomonitor.Checked;
            myProp.noRegex = cbnoRegex.Checked;
            myProp.noStop = cbNostop.Checked;
            myProp.PvDisable = tbDis.Text;
            myProp.PvFlag = tbFlag.Text;
            dlgSv.ShowDialog();
            myProp.saveMe(dlgSv.FileName);
            
        }

        private void btAdd_Click(object sender, EventArgs e)
        {
            lbPv.Items.Add(tbPv.Text);
            string[] msgArray = Regex.Split(tbPv.Text, ";");
            myProp.Values.Add(msgArray[0], msgArray[1]);
        }

        private void btopen_Click(object sender, EventArgs e)
        {
            dlgOp.ShowDialog();
            myProp = TranmeterProp.loadMe(dlgOp.FileName);
            cbIsbyte.Checked= myProp.isByte;
            cbIshost.Checked = myProp.isHost;
            tbMask.Text= myProp.mask ;
              tbTemplate.Text=myProp.myTemplate;
             tbName.Text=myProp.Name ;
              cbNomonitor.Checked=myProp.noMonitor;
            cbnoRegex.Checked  =myProp.noRegex;
            cbNostop.Checked = myProp.noStop;
              tbDis.Text =myProp.PvDisable;
              tbFlag.Text=myProp.PvFlag;
              lbPv.Items.Clear();
            int i=0;  
            for (i=0;i<myProp.values.Count;i++)
              {
                  lbPv.Items.Add(myProp.values[i] + ";" + myProp.props[i]);
              }

        }
    }
}
